<?php

namespace App\Models;

use App\User;
use Illuminate\Database\Eloquent\Model;

class Clue extends Model
{
    public $timestamps = false;

    protected $casts = [
        'remark_dict' => 'json'
    ];

    protected $fillable = [
        'account_id',
        'type',
        'clue_id',
        'adv_id',
        'ad_plan_id',
        'ad_plan_name',
        'site_id',
        'clue_type',
        'module_id',
        'create_time',
        'clue_source',
        'gender',
        'age',
        'remark_dict',
        'external_url',
        'module_name',
        'name',
        'email',
        'weixin',
        'qq',
        'province_name',
        'city_name',
        'address',
        'remark',
        'form_remark',
        'appname',
        'convert_status',
        'telphone',
    ];

    public function account()
    {
        return $this->belongsTo(Account::class);
    }

    public function action()
    {
        return $this->hasMany(ClueAction::class, 'clue_id', 'id');
    }

    public function callLog()
    {
        return $this->hasMany(ClueCallLog::class, 'clue_id', 'id');
    }

    public function distributions()
    {
        return $this->belongsToMany(User::class, 'clue_distributions', 'clue_id', 'user_id');
    }

    public function tags()
    {
        return $this->belongsToMany(ClueTag::class, 'clue_has_tags', 'clue_id', 'tag_id');
    }

}
